package com.caiyi.tips.core.VO;

import com.caiyi.tips.core.enums.ResultEnum;
import lombok.Data;

import java.io.Serializable;

/*
 * 标准返回对象
 * @author Cliff.ZhouYang
 * @date 2017/11/8 15:21
 */
@Data
public class ResultVO<T> implements Serializable {
    private String code;

    private String msg;

    private T data;

    public ResultVO(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultVO(String code, T data) {
        this.code = code;
        this.data = data;
    }

    public ResultVO(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功+msg
     * @param msg
     * @return
     */
    public static ResultVO okMsg(String msg) {
        return new ResultVO(ResultEnum.SUCCESS.getCode(), msg);
    }

    /**
     * 成功+数据
     * @param data
     * @return
     */
    public static ResultVO okData(Object data) {
        return new ResultVO(ResultEnum.SUCCESS.getCode(), data);
    }

    /**
     * 成功+msg+数据
     * @param msg
     * @param data
     * @return
     */
    public static ResultVO okMsgData(String msg, Object data) {
        return new ResultVO(ResultEnum.SUCCESS.getCode(), msg, data);
    }

    /**
     * 失败 系统错误500+error
     * @return
     */
    public static ResultVO fail() {
        return new ResultVO(ResultEnum.SYSTEM_ERROR.getCode(), "error");
    }
    /**
     * 失败code+msg
     * @param code
     * @param msg
     * @return
     */
    public static ResultVO fail(String code, String msg) {
        return new ResultVO(code, msg);
    }

    /**
     * 失败 默认code500 +msg
     * @param msg
     * @return
     */
    public static ResultVO failMsg(String msg) {
        return new ResultVO(ResultEnum.SYSTEM_ERROR.getCode(), msg);
    }
    /**
     * 失败code+msg+数据
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static ResultVO failData(String code, String msg, Object data) {
        return new ResultVO(code, msg, data);
    }
}
